package com.ages.input;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.awt.event.*;

/**
 *
 * @author felix
 */
public class Keyboard implements KeyListener {
   
   
    private boolean space,up,down,left,right,plus,minus,enter,esc,backspace;
    private String letter;
    private boolean letterTimeout = false;
    
        public boolean up(){return up;}
        public boolean down(){return down;}
        public boolean right(){return right;}
        public boolean left(){return left;}
        public boolean space(){return space;}
        public boolean plus(){return plus;}
        public boolean minus(){return minus;}
        public boolean enter(){return enter;}
        public boolean esc(){return esc;}
        public boolean backspace(){return backspace;}

        public String letter() {
        
            if (letterTimeout)
            {
                letterTimeout = false;
                return letter;
            }
            return "";
        }
        
    public Keyboard() {
        super();
        letter = "";
        letterTimeout = false;

    }

    public void keyTyped(KeyEvent e) {
        letter = String.valueOf(e.getKeyChar());
        letterTimeout = true;
    }

    public void keyPressed(KeyEvent e) {
//        System.out.println("omg pressed:"+e);
        switch (e.getKeyCode()) {
            case KeyEvent.VK_PLUS : plus = true; break;
            case 107 : plus = true; break;
            case 109 : minus = true; break;
            case KeyEvent.VK_MINUS : minus = true; break;
            case KeyEvent.VK_SPACE : space = true; break;
            case KeyEvent.VK_UP : up = true; break;
            case KeyEvent.VK_DOWN : down = true; break;
            case KeyEvent.VK_LEFT : left = true; break;
            case KeyEvent.VK_RIGHT : right = true; break;
            case KeyEvent.VK_ENTER : enter = true; break;
            case KeyEvent.VK_ESCAPE : esc = true; break;
            case KeyEvent.VK_BACK_SPACE : backspace = true; break;
        }
        

    }
    
    public void keyReleased(KeyEvent e) {
        switch (e.getKeyCode()) {
            case KeyEvent.VK_PLUS : plus = false; break;
            case KeyEvent.VK_MINUS : minus = false; break;
            case 107 : plus = false; break;
            case 109 : minus = false; break;
            case KeyEvent.VK_SPACE : space = false; break;
            case KeyEvent.VK_UP : up = false; break;
            case KeyEvent.VK_DOWN : down = false; break;
            case KeyEvent.VK_LEFT : left = false; break;
            case KeyEvent.VK_RIGHT : right = false; break;
            case KeyEvent.VK_ENTER : enter = false; break;
            case KeyEvent.VK_ESCAPE : esc = false; break;
            case KeyEvent.VK_BACK_SPACE : backspace = false; break;
        }
        letter="";
    } 
    

}
